import 'package:app_30/models/gogngao_entity.dart';
import 'package:app_30/models/load_entity.dart';
import 'package:app_30/models/vip_entity.dart';
import 'package:app_30/net/dio_utils.dart';
import 'package:app_30/net/http_api.dart';
import 'package:app_30/util/cache_utils.dart';
import 'package:app_30/util/dialog_utils.dart';
import 'package:flutter/widgets.dart';

class VipViewModel extends ChangeNotifier {
  String title = 'VIP';

  String? description;
  GonggaoEntity? gongGao;
  LoadEntity? loadData;
  VipEntity? vipData;

  void initialise() {
    if (getVipData()!.cuetxt != null) {
      description = Uri.decodeQueryComponent(getVipData()!.cuetxt!);
    }
    gongGao = getGonggao();
    loadData = getLoadData();
    vipData = getVipData();
    title = 'VIP';


    notifyListeners();
    Future.delayed(Duration(seconds: 1), (){
      title = "VIPD";
    });
  }

  getFreevip(context) async {
    Map<String, dynamic> map = Map();
    map['user'] = "${loadData?.user}";
    map['mysqlid'] = "${loadData?.id}";
    map['tgjifen'] = "${loadData?.tgjifen}";
    map['tgfennum'] = "${vipData?.tgfennum}";
    map['tjrnum'] = "${vipData?.tjrnum}";
    map['vip'] = "${loadData?.vip}";
    map['time'] = "";
    await DioUtils.instance.requestNetwork<String>(
      Method.post,
      HttpApi.getfreevip,
      params: map,
      onSuccess: (data) {
        showMultipleDialog(
          context,
          'vip开通!',
          positiveAction: () => Navigator.of(context).pop(),
        );
      },
      onError: (_, __) {
        showSingleDialog(
          context,
          '${__}',
        );
      },
    );
  }
}
